package com.example.bighomework.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.bighomework.R;

import org.checkerframework.checker.nullness.qual.NonNull;

public class HourlyWeatherAdapter extends RecyclerView.Adapter<HourlyWeatherAdapter.HourlyViewHolder> {
    private String[] times;
    private double[] temperatures;

    public HourlyWeatherAdapter(String[] times, double[] temperatures) {
        this.times = times;
        this.temperatures = temperatures;
    }

    @NonNull
    @Override
    public HourlyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_hourly_weather, parent, false);
        return new HourlyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull HourlyViewHolder holder, int position) {
        holder.timeTextView.setText(times[position].substring(11));
        holder.temperatureTextView.setText(temperatures[position] + "°C");
    }

    @Override
    public int getItemCount() {
        return times.length;
    }

    public class HourlyViewHolder extends RecyclerView.ViewHolder {
        TextView timeTextView;
        TextView temperatureTextView;

        public HourlyViewHolder(@NonNull View itemView) {
            super(itemView);
            timeTextView = itemView.findViewById(R.id.hour_time);
            temperatureTextView = itemView.findViewById(R.id.hour_temperature);

        }
    }
}